# Copyright 2024 Ant Group Co., Ltd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

load("@trustedflow//bazel:trustedflow.bzl", "trustedflow_cc_library")

package(default_visibility = ["//visibility:public"])

config_setting(
    name = "sgx2",
    values = {"define": "tee_type=sgx2"},
)

config_setting(
    name = "csv",
    values = {"define": "tee_type=csv"},
)

config_setting(
    name = "tdx",
    values = {"define": "tee_type=tdx"},
)

trustedflow_cc_library(
    name = "generator_wrapper",
    srcs = ["generator_wrapper.cc"],
    hdrs = ["generator_wrapper.h"],
    copts = select({
        ":sgx2": ["-DTEE_TYPE_SGX2"],
        ":tdx": ["-DTEE_TYPE_TDX"],
        ":csv": ["-DTEE_TYPE_CSV"],
        "//conditions:default": [],
    }),
    deps = select({
        ":sgx2": ["//trustedflow/attestation/generation/sgx2:sgx2_generator"],
        ":tdx": ["//trustedflow/attestation/generation/tdx:tdx_generator"],
        ":csv": ["//trustedflow/attestation/generation/csv:csv_generator"],
        "//conditions:default": [],
    }) + [
        "//trustedflow/attestation/common:constants",
        "//trustedflow/attestation/common:status",
        "//trustedflow/attestation/generation/interface:generator",
        "//trustedflow/attestation/utils:json2pb",
        "@yacl//yacl/base:exception",
    ],
)

trustedflow_cc_library(
    name = "generator_wrapper_c_api",
    srcs = ["generator_wrapper_c_api.cc"],
    hdrs = ["generator_wrapper_c_api.h"],
    deps = [
        ":generator_wrapper",
    ],
)

cc_binary(
    name = "libgeneration.so",
    srcs = [
        "generator_wrapper_c_api.cc",
    ],
    linkshared = True,
    deps = [
        ":generator_wrapper_c_api",
    ],
)
